package io.bdmc.modules.bss.controller;

import io.bdmc.common.annotation.SysLogger;
import io.bdmc.common.utils.MyPage;
import io.bdmc.common.utils.R;
import io.bdmc.modules.bss.entity.DeviceRouteSnapshot;
import io.bdmc.modules.bss.model.SnapshotParam;
import io.bdmc.modules.bss.service.IDeviceRouteSnapshotService;
import io.bdmc.modules.sys.controller.AbstractController;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

/**
 * <p>
 * 路由快照 前端控制器
 * </p>
 *
 * @author 黄露
 * @since 2021-05-28
 */

// "路由快照", description = "路由快照")
@RestController
@RequestMapping("/bss/route/snapshot")
public class DeviceRouteSnapshotController extends AbstractController {

    @Autowired
    IDeviceRouteSnapshotService _deviceroutesnapshotSvs;

    @GetMapping("/list")
    // "分页查询路由快照", notes = "分页查询路由快照")
    public R list(SnapshotParam params) {
        MyPage<DeviceRouteSnapshot> myPage = new MyPage<DeviceRouteSnapshot>(params.getCurrent(), params.getSize());
        myPage = _deviceroutesnapshotSvs.mySelectPage(myPage);
        return R.ok().putPageData(myPage.getRecords(), myPage.getTotal());

    }

    @SysLogger("新增路由快照")
    @PostMapping("/add")
    // "新增路由快照", notes = "新增路由快照")
    // @RequiresPermissions("bss:deviceRouteSnapshot:add")
    public R add(@RequestBody DeviceRouteSnapshot deviceroutesnapshot) {
        // deviceroutesnapshot.setCreateBy(getUser().getUsername());
        deviceroutesnapshot.setDataTime(LocalDateTime.now());
        // deviceroutesnapshot.setDeptId(getDeptId());
        Boolean b = deviceroutesnapshot.insert();
        return R.trueOrFalse(b);
    }

    @SysLogger("修改路由快照")
    @PostMapping("/update")
    // "修改路由快照", notes = "修改路由快照")
    // @RequiresPermissions("bss:deviceRouteSnapshot:update")
    public R update(@RequestBody DeviceRouteSnapshot deviceroutesnapshot) {
        Boolean b = deviceroutesnapshot.updateById();
        return R.trueOrFalse(b);
    }

    @SysLogger("删除路由快照")
    @DeleteMapping("/delete/{snapshotId}")
    // "删除路由快照", notes = "删除路由快照")
    // @RequiresPermissions("bss:deviceRouteSnapshot:delete")
    public R delete(@PathVariable Integer snapshotId) {
        if (snapshotId > 0)
            _deviceroutesnapshotSvs.removeById(snapshotId);
        return R.ok();
    }
}
